// photoproductlist.js
var app = getApp()
var host = app.globalData.host
Page({
  data: {
    photolist:'',
    image: app.globalData.image
  },
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: host + '/spuApi/spuClassifyDetail?id=dc65749dead64e43aed964c0c8f7271e&pageNo=1&type=1',
      header: { 'content-type': 'application/json' },
      success: function (res) {
        var list = res.data.data
        that.setData({
          photolist: list
        })
        list.map(item => {
          if (wx.getStorageSync(that.data.image + item.photo)) {
            return item
          } else {
            wx.downloadFile({
              url: that.data.image + item.photo,
              success: function (res) {
                console.log("item.photo:" + item.photo + ",res.temp=" + res.tempFilePath)
                wx.setStorageSync(that.data.image + item.photo, res.tempFilePath)
              }
            })
            return item
          }
        })

        
      }
    })
  },
  tophoto:function(e){
    var id = e.currentTarget.dataset.photoid
    wx.redirectTo({
      url:"../photoproductdetail/photoproductdetail?id="+id
    })
  }
})